//
//  CZLoginViewController.m
//  notification-test
//
//  Created by Song on 2018/6/19.
//  Copyright © 2018年 Song. All rights reserved.
//

#import "CZLoginViewController.h"

#define GSYNAME @"updateLoginInfo"

@interface CZLoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
- (IBAction)cancel:(id)sender;
- (IBAction)login:(id)sender;

@end

@implementation CZLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // name 成为第一响应者
//    [self.nameField becomeFirstResponder];
}

// 发送通知
-(void)postNotificationMethod {
    // 附加信息
    NSDictionary *userInfo = @{@"loginInfo" : [NSString stringWithFormat:@"hello,%@",self.nameField.text]};
    // 发送带有附加信息的通知
    [[NSNotificationCenter defaultCenter] postNotificationName:GSYNAME object:self userInfo:userInfo];    
}

// 取消
- (IBAction)cancel:(id)sender {
    [self.view endEditing:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
}

// 登录按钮
- (IBAction)login:(id)sender {
    // 发送通知
    [self postNotificationMethod];
    [self dismissViewControllerAnimated:YES completion:nil];
}
@end
